<?
 require_once("functions.php");


function addVendor($newVendor)
{

	$database = getDB();
	
	$newVendor = arrayEscape($newVendor, $database);
	
	$statement = "INSERT INTO Vendor SET name = '$newVendor[name]'";

	$results = $database->query($statement);

	$error = $database->error;

	$database->close();
	
	return $error == '' ? true : array('SQL Error' => $error);
}

function blank_vendor()
{
	return array('id'=>null, 'created'=>null, 'updated'=>null, 'created_by'=>null, 'updated_by'=>null, 'name'=>null);
}

function delVendor($idVendor)
{

	$database = getDB();

	$statement = "DELETE FROM Vendor WHERE id = '$idVendor'";

	$results = $database->query($statement);

	$error = $database->error;

	$database->close();
	
	return $error == '' ? true : array('SQL Error' => $error);
}

function editVendor($updatearray)
{

	$database = getDB();
	
	$updatearray = arrayEscape($updatearray, $database);

	$statement = "UPDATE Vendor SET name = '$updatearray[name]' WHERE id = '$updatearray[id]'";

	$results = $database->query($statement);

	$error = $database->error;

	$database->close();
	
	return $error == '' ? true : array('SQL Error' => $error);

}

function getVendor($idVendor)
{

	$database = getDB();

	$statement = "SELECT * FROM Vendor WHERE id = '$idVendor'";

	$results = $database->query($statement);

	$vendor = $results->fetch_assoc();

	$database->close();
	
	return $vendor;
}

function getVendors()
{

	$database = getDB();

	$statement = "SELECT * FROM Vendor ORDER BY name ASC";

	$results = $database->query($statement);

	$database->close();
	
	return $results;
}
?>
